<form action="#" class="layui-form">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label>名称:</label>
            <div class="layui-inline">
                <input type="text" name="name" autocomplete="off" placeholder="请输入名称"
                       class="layui-input">
            </div>
            <button class="layui-btn" lay-submit lay-filter="systemparamter-table">搜索</button>
        </div>
    </div>
</form>
<script type="text/html" id="aviation-head-bar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="goEdit"><i class="layui-icon">&#xe654;</i>添加</button>
        <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="delete"><i class="layui-icon">&#xe640;</i>删除
        </button>
    </div>
</script>
<script type="text/html" id="aviation-aviation-bar">
    <a class="layui-btn layui-btn-xs" lay-event="edit-aviation">编辑</a>
</script>
<table class="layui-table" lay-filter="aviation-table" id="aviation-table">
</table>
<script type="text/javascript" >
    layui.use(['table', 'layer', 'form'], function () {
        var table = layui.table;
        var layer = layui.layer;
        var form = layui.form;
        form.render();
        table.render({
            id: "aviation-table",
            elem: '#aviation-table'
            , toolbar: '#aviation-head-bar'
            , cellMinWidth: 80
            , url: '/aviation/table' //数据接口
            , page: true //开启分页
            , cols: [[
                {checkbox: true},
                {field: 'id', title: 'ID', sort: true}
                // , {field: 'parentId', title: '入住城市'}
                , {field: 'aviationCompany', title: '航空公司'}
                , {field: 'aviationCabin', title: '舱位'}
                , {field: 'aviationNumber', title: '航空编号'}
                , {fixed: 'right', title: '操作', toolbar: '#aviation-aviation-bar', width: 180}
            ]]
        });
        //头工具栏
        table.on('toolbar(aviation-table)', function (obj) {
            switch (obj.event) {
                case 'goEdit':
                    openEditWindow(null);
                    break;
                case 'delete':
                    var data = table.checkStatus('aviation-table').data;
                    if (data.length > 0) {
                        layer.confirm('真的删除行么', function (index) {
                            var param = ""
                            $.each(data, function (i, obj) {
                                param += "&ids=" + obj.id
                            })
                            $.ajax({
                                url: '/aviation/deleteBatchIds',
                                data: param,
                                method: 'post',
                                success: function (result) {
                                    if (result.status) {
                                        table.reload('aviation-table', {});
                                    } else {
                                        alert(result.message)
                                    }
                                    layer.close(index);
                                }
                            })
                        });
                    }
                    break;
            }
            ;
        ;
    });
    //监听行工具事件
    table.on('tool(aviation-table)', function (obj) {
        var data = obj.data;
        switch (obj.event) {
            case 'edit-aviation': {
                openEditWindow(data);
                break;
            }

        }
    });

    function openEditWindow(data) {
        layer.open({
            type: 1,
            content: $('#aviation-edit-layer').html(),
            title: '编辑'
            , area: ['500px', '400px'],
            btn: ['提交', '取消'] //可以无限个按钮
            , yes: function (index, layero) {
                layer.load()
                $.ajax({
                    url: "/aviation/" + (data == null ? 'add' : 'update'),
                    data: $("#aviation-edit-form").serialize(),
                    method: 'post',
                    success: function (result) {
                        if (result.status) {
                            table.reload('systemparamter-table', {});
                            layer.close(index);
                        } else {
                            alert(result.message)
                        }

                        layer.closeAll('loading');
                    }
                })
            }, success: function (layero, index) {
                form.render()
                if (data != null) {
                    form.val("aviation-edit-form", data);
                    form.val("aviation-edit-form", {
                        "state": data.state + ""
                    });
                }
            }
        });
    }

    form.on('submit(aviation-table)', function (data) {
        table.reload('aviation-table', {
            page: {
                curr: 1 //重新从第 1 页开始
            },
            where: data.field
        });
        return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });

    })
    ;

</script>

<script type="text/html" id="aviation-edit-layer">
    <form id="aviation-edit-form" style="width: 80%" class="layui-form" lay-filter="aviation-edit-form">
        <input type="hidden" name="id">
        <div class="layui-form-item">
            <label class="layui-form-label">航空公司</label>
            <div class="layui-input-block">
                <input type="text" name="aviationCompany" required lay-verify="required" placeholder="请请输入航空公司"
                       autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">舱位</label>
            <div class="layui-input-block">
                <input type="text" name="aviationCabin" required lay-verify="required" placeholder="请请输入舱位"
                       autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">航空编号</label>
            <div class="layui-input-block">
                <input type="text" name="aviationNumber" required lay-verify="required" placeholder="请请输入航空编号"
                       autocomplete="off"
                       class="layui-input">
            </div>
        </div>

    </form>
</script>